package com.smile.stream.stream;

import com.smile.stream.StreamUtil;
import com.smile.stream.pojo.Dish;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

/**
 * @author LiYuhang
 * @version 0.1
 * @application
 * @Date 2021/10/7 17:58
 */
public class StreamDemo4 {
    public static void main(String[] args) {
       findAny();
       findFirst();
    }

    private static void findFirst() {
        List<Integer> someNumbers = Arrays.asList(1, 2, 3, 4, 5);
        Optional<Integer> firstSquareDivisibleByThree =
                someNumbers.stream()
                        .map(x -> x * x)
                        .filter(x -> x % 3 == 0)
                        .findFirst();
        System.out.println(firstSquareDivisibleByThree);
    }

    private static void findAny() {
        StreamUtil.getMenu()
                .stream()
                .filter(Dish::isVegetarian)
                .findAny()
                .ifPresent(d -> System.out.println(d.getName()));
    }
}
